<template>
  <div>
    <div class="time">统计截至{{ WomWorld.lastUpdateTime }}</div>
    <!-- 海外疫情累计数据卡片 -->
    <div class="hotBox">
      <van-row>
        <van-col span="6">
          <p class="yesterday">
            较昨日<span class="yesterday1">{{
              WomWorld.nowConfirmAdd | num
            }}</span>
          </p>
          <p class="yesterday1 strong">
            {{ WomWorld.nowConfirm | toLocale }}
          </p>
          <strong>现存确诊</strong>
        </van-col>
        <van-col span="6">
          <p class="yesterday">
            较昨日<span class="yesterday2">{{
              WomWorld.confirmAdd | num
            }}</span>
          </p>
          <p class="yesterday2 strong">
            {{ WomWorld.confirm | toLocale }}
          </p>
          <strong>累计确诊</strong></van-col
        >
        <van-col span="6">
          <p class="yesterday">
            较昨日<span class="yesterday3">{{ WomWorld.deadAdd | num }}</span>
          </p>
          <p class="yesterday3 strong">
            {{ WomWorld.dead | toLocale }}
          </p>
          <strong>累计死亡</strong></van-col
        >
        <van-col span="6">
          <p class="yesterday">
            较昨日<span class="yesterday4">{{ WomWorld.healAdd | num }}</span>
          </p>
          <p class="yesterday4 strong">
            {{ WomWorld.heal | toLocale }}
          </p>
          <strong>累计治愈</strong></van-col
        >
      </van-row>
    </div>
    <!-- 海外疫情表 -->
    <div class="boxlist">
      <strong class="title">海外疫情</strong>
      <div class="list-nav">
        <van-row>
          <van-col span="5">地区</van-col>
          <van-col span="5">新增确诊</van-col>
          <van-col span="5">累计确诊</van-col>
          <van-col span="5">治愈</van-col>
          <van-col span="4">死亡</van-col>
        </van-row>
      </div>
      <!-- 列表渲染区域 -->
      <div class="list">
        <van-row v-for="(item, index) in WomAboard" :key="index">
          <van-col span="5">{{ item.name }}</van-col>
          <van-col span="5">{{ item.confirmAdd }}</van-col>
          <van-col span="5">{{ item.confirmAdd }}</van-col>
          <van-col span="5">{{ item.heal }}</van-col>
          <van-col span="4">{{ item.dead }}</van-col>
        </van-row>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "MyGuowai",
  data() {
    return {
      WomWorld: {}, //疫情数据
      WomAboard: [], //疫情地区数据
    };
  },
  mounted() {
    // this.getCovWorld();
    this.getWorldCov();
  },
  methods: {
    // getCovWorld() {
    //   this.$api.reqCovWorld().then((res) => {
    //     console.log(res.data);
    //     this.WomWorld = res.data.data.WomWorld;
    //     this.WomAboard = res.data.data.WomAboard.splice(0, 50);
    //   });
    // },
    async getWorldCov() {
      const data = await this.$api.reqWorldCov();
      console.log(data);
      this.WomWorld = data.data.worldCov.WomWorld;
      this.WomAboard = data.data.worldCov.WomAboard;
    },
  },
  filters: {
    num(val) {
      return val > 0 ? "+" + val : "-" + val;
    },
    toLocale(val) {
      return Number(val).toLocaleString();
    },
  },
};
</script>

<style scoped lang="scss">
.time {
  margin: 0.2rem 0.2rem;
  font-size: 12px;
  color: #999;
}
.hotBox {
  display: flex;
  justify-content: center;
  border-radius: 0.08rem;
  padding: 0.2rem 0 0.2rem 0;
  box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
  // text-align: center;

  .van-col {
    // background-color:#ff5555 ;
    padding: 0 0.15rem;
    > strong {
      font-size: 12px;
      color: #1a1a1a;
      // font-weight: 400;
    }
    .yesterday {
      width: 1.4rem;
      color: #999;
      font-size: 10px;
    }
    .yesterday1 {
      color: #ff5555;
    }
    .yesterday2 {
      color: green;
    }
    .yesterday3 {
      color: #909046;
    }
    .yesterday4 {
      color: purple;
    }
    // .yesterday5 {
    //   color: yellowgreen;
    // }
    // .yesterday6 {
    //   color: blue;
    // }
    .strong {
      font-weight: 700;
      font-size: 14px;
      padding: 0.05rem 0;
    }
  }
  // .van-col:nth-child(1) {
  //   background-color: #141010;
  // }
}
.boxlist {
  margin: 0.2rem 0.2rem;
  .title {
  }
  .van-col {
    text-align: center;
    font-size: 14px;
    line-height: 0.7rem;
  }
  .list-nav {
    position: sticky;
    top: 0.2rem;
    margin-top: 0.2rem;
    .van-col:nth-child(1) {
      background-color: #909046;
    }
    .van-col:nth-child(2) {
      background-color: #145370;
    }
    .van-col:nth-child(3) {
      background-color: #b4afcc;
    }
    .van-col:nth-child(4) {
      background-color: #cfb1b8;
    }
    .van-col:nth-child(5) {
      background-color: #c2dee2;
    }
  }
  .list {
    .van-col {
      text-align: center;
      font-size: 12px;
      line-height: 0.7rem;
      border-bottom: 1px solid #eee;
      /*第一步： 溢出隐藏 */
      overflow: hidden;
      /* 第二步：让文本不会换行， 在同一行继续 */
      white-space: nowrap;
      /* 第三步：用省略号来代表未显示完的文本 */
      text-overflow: ellipsis;
    }
    .van-col:nth-child(1) {
      text-align: left;
      padding-left: 0.5rem;
    }
  }
}
</style>